package com.tanhua.server.controller;

import com.tanhua.server.service.PeachblossomService;
import com.tanhua.server.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Created by ${smh} on 2020/12/9.
 */
@RestController
@RequestMapping("peachblossom")
public class PeachblossomController {


    @Autowired
    private PeachblossomService peachblossomService;

    /**
     * 发送语音
     * @param soundUrl
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> saveSound(@RequestParam("soundFile")MultipartFile soundUrl){

        try {
            this.peachblossomService.saveSound(soundUrl);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }

    /**
     * 接收语音
     * @return
     */
    @GetMapping
    public ResponseEntity<SoundVo> querySound(){

        try {
            SoundVo soundVo = this.peachblossomService.querySound();
            return ResponseEntity.ok(soundVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }


}
